<?php
session_start();
require_once 'lib/function.php';
if(isset($_GET['a'])){
    if($_GET['a']=='out'){
        if(isset($_SESSION['admin']))
        {
            unset($_SESSION['admin']);
            unset($_SESSION['admin_post']);
        }
    }
}
if($_POST!=null){
        $user = isset($_POST['user'])?$_POST['user']:'';
        $pwd = isset($_POST['pwd'])?$_POST['pwd']:'';
        if($user==''||$pwd==''){
            echo "<script>alert('用户名或密码不能为空!');location.href='login.html';</script>";
        }
        else{
            $sql = "select admin_post,admin_id,admin_password,admin_name from adminlogin where admin_email='{$user}'";
            $res = getAllData($sql);
            $res = $res[0];
            if($res!=null){

                if($res['admin_password']==$pwd){
                    $_SESSION['admin']=$res['admin_name'];
                    $_SESSION['admin_post']=$res['admin_post'];
                    echo "<script>alert('登录成功!');location.href='main_panel.php';</script>";
                }
                else{
                    echo "<script>alert('密码不正确!');location.href='login.html';</script>";
                }
            }else{
                echo "<script>alert('用户名不存在!');location.href='login.html';</script>";
            }
        }
    }


    include 'login.html';
